package com.song.boot.springstudy.netty.adhesivedisassembly;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.StandardCharsets;

class ClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        // 发送100条消息，演示粘包问题
        for (int i = 0; i < 100; i++) {
            ByteBuf buffer = ctx.alloc().buffer();
            // buffer.writeBytes(("hello, server" + i).getBytes(StandardCharsets.UTF_8));
            // 行分隔符解码器 LineBasedFrameDecoder \n
            buffer.writeBytes(("hello, server-----fsfsdfsdsfsdfsdfsdf-" + i+"\n").getBytes(StandardCharsets.UTF_8));
            ctx.writeAndFlush(buffer);
        }
    }
}